package com.rk.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rk.admin.aop.SystemControllerLog;
import com.rk.admin.domain.Briefinfo;
import com.rk.admin.domain.Comarticle;
import com.rk.admin.mapper.ComarticleMapper;
import com.rk.admin.service.ComarticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ComarticleServiceImpl implements ComarticleService {
    
    @Autowired
    private ComarticleMapper comarticleMapper;

    /**
     * 添加文章
     * @param comarticle
     * @return
     */
    @Override
    @SystemControllerLog(description ="添加合作交流文章")
    public Boolean add(Comarticle comarticle) {
        return comarticleMapper.insertComarticle(comarticle)>0;
    }


    /**
     * 条件分页查询
     * @param page
     * @param limit
     * @param title
     * @return
     */
    @Override
    public IPage<Comarticle> selectPage(int page, int limit, String title) {

        IPage<Comarticle> pageinfo=new Page<>(page,limit);
        LambdaQueryWrapper<Comarticle> lqw=new LambdaQueryWrapper<Comarticle>();
        //根据创建时间降序
        lqw.orderByDesc(Comarticle::getCreatime);

        //查询指定字段
        lqw.select(Comarticle::getId,Comarticle::getTitle,Comarticle::getCreatime,Comarticle::getModel);

        //根据文章标题进行条件查询
        if(!"".equals(title)&&title!=null){
            lqw.like(Comarticle::getTitle,title);
        }

        comarticleMapper.selectPage(pageinfo,lqw);
        return pageinfo;
    }


    /**
     * 通过id删除文章
     *
     * @param id
     * @return
     */
    @Override
    public Boolean deleteById(Integer id) {
        return comarticleMapper.deleteById(id)>0;
    }

    /**
     * 通过id修改
     * @param comarticle
     * @return
     */
    @Override
    public Boolean updatebyId(Comarticle comarticle) {

        return comarticleMapper.updatebyid(comarticle)>0;
    }

    /**
     * 通过id查找
     *
     * @param id
     * @return
     */
    @Override
    public Comarticle findbyId(Integer id) {
        return comarticleMapper.queryById(id);
    }
}
